﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;


namespace SalesVMT
{
    public class SQLServerUtil
    {
        public static SqlConnection CreateConnection()
        {
            SqlConnection conn = new SqlConnection(Properties.Settings.Default.SalesVMTConn);
            return conn;
        }
        public static SqlConnection CreateConnectionBackup()
        {
            SqlConnection conn = new SqlConnection(Properties.Settings.Default.BKSalesVMTConn);
            return conn;
        }
        public static DataSet Query(string sqlQuery)
        {
            DataSet retVal = null;
            SqlConnection dbConn = CreateConnection();

            SqlCommand dbCmd = new SqlCommand(sqlQuery, dbConn);
            dbCmd.CommandType = CommandType.Text;

            try
            {
                retVal = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }
        public static bool Query1(string sqlQuery)
        {
            bool retVal = false;
            SqlConnection dbConn = CreateConnection();
            SqlCommand dbCmd = new SqlCommand(sqlQuery, dbConn);
            dbCmd.CommandType = CommandType.Text;
            try
            {
                dbConn.Open();
                dbCmd.ExecuteNonQuery();
                retVal = true;
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }
    }
}
